<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Kalendář</title>
  <link rel="stylesheet" type="text/css" href="../css/calendar.css">
</head>
  
<body>
<script>
var monthNames=new Array("Led","Úno","Bře","Dub","Kvě","Čer","Čec","Srp","Zář","Říj","Lis","Pro");
var dayNames=new Array("Po","Út","St","Čt","Pá","So","Ne");
var theMonth, theYear, theTime;
var onlyDate = false;

function WriteCell( type, day ) {
       switch(type){
        case 0:
          document.write("<th></th>");
          break;
        case 1:
          document.write("<td><a href='javascript:Transfer("+day+")'>"+day+"</a></td>");
          break;
        case 2:
          document.write("<td><a class='today' href='javascript:Transfer("+day+")'>"+day+"</a></td>");
          break;
       }
}

function IsToday( d, m, y ) {
var myDate= new Date();
        if ( (myDate.getDate()== d) &&
             (myDate.getMonth() == m) &&
             (myDate.getFullYear() == y) )        {
             return true
        }
        return false
}

function ChangeDate(the_month,the_year) {
        var URL = location.href
        var i = URL.indexOf("?")
        if (i != -1) {
        	URL = URL.slice(0,i);
        }

		URL += "?";
        
        if(onlyDate) {
			URL += "onlyDate&";
        }
		
        URL += ( "month=" + the_month + "&year=" + the_year );
        
        if(!onlyDate) {
        	the_time = document.cal_time.match_time.value;
        	URL += ( "&time=" + the_time );
        }
      
        location.href = URL
}

function WriteNavigation(the_month,the_year) {
    document.write("<table id='calendar-nav' cellspacing='1'>");
    document.write("<tr><td colspan=12 class='year'><a href='javascript:ChangeDate("+the_month+","+(the_year-1)+")'>&lt;&lt;</a>")
    document.write(the_year)
    document.write("<a href='javascript:ChangeDate("+the_month+","+(the_year+1)+")'>&gt;&gt;</a></td>")
    document.write("</tr><tr>")
    for(var i = 0; i < 12; i++ ) {
        if(i == the_month) {
                document.write("<td class='today'>" + monthNames[i] + "</td>")
        } else {
                document.write("<td><a class='month' href='javascript:ChangeDate("+i+","+the_year+")'>" + monthNames[i] + "</a></td>")
        }
    }
    document.write("</tr></table>")
}

function WriteMonthTable(the_month,the_year) {
var cellColor
var day_counter=1;
var first_day= new Date(the_year,the_month,1);
    first_day=first_day.getDay();
    first_day=first_day==0?6:first_day-1
var day_in_month=31;
    if (the_month == 3 || the_month == 5 || the_month == 8 || the_month == 10) {
        day_in_month=30;
    }
    if (the_month == 1) {
        day_in_month=28;
        if ( ((the_year % 4 == 0) && (the_year % 100 != 0)) || (the_year % 400 == 0) ) {
                day_in_month=29;
        }
    }

    document.write("<table id='calendar-days' cellspacing='1'>");

    // Zahlavi dnu
    document.write("<tr>");
    for( var i=0; i<7; i++ ) {
        document.write("<th>"+ dayNames[i] + "</th>");
    }
    document.write("</tr>")

    // Prvni radek tabulky
    document.write("<tr>");
    for (i = 0; i < first_day; i++) {
        WriteCell(0, 0)
    }
    for (i = first_day; i < 7; i++) {
        if(IsToday(day_counter, the_month, the_year))
          WriteCell(0, day_counter)
        else
          WriteCell(1, day_counter)
        day_counter=day_counter + 1;
    }
    document.write("</tr>");

    // Dalsi radky
    for (a = 1; a < 6; a++) {
        document.write("<tr>");
        var header;
        for (b = 0; b < 7; b++) {
                if(IsToday(day_counter, the_month, the_year))
                  WriteCell(2, day_counter)
                else
                  WriteCell(1, day_counter)
                if (day_counter >= day_in_month){
                        for (i = b; i < 6; i++) {
                                WriteCell(0, 0)
                        }
                        b = 7;
                        a = 5;
                }
                day_counter=day_counter + 1;
        }
        document.write("</tr>");
    }
    document.write("</table>");
}

function WriteTime(theTime){
  document.write("<form name='cal_time'>Čas <input maxlength='5' type='text' name='match_time' id='match_time'></form>");
  document.cal_time.match_time.value = theTime;
}


function Transfer( day ) {  
    theMonth = theMonth + 1;
    if (theMonth < 10) theMonth = "0" + theMonth;
    if (day < 10) day = "0" + day;
    theValue = "" + theYear + "-" + theMonth + "-" + day; 
	if(!onlyDate){
		theTime = document.cal_time.match_time.value;
	    if(theTime != "") theTime= " " + theTime;
	    theValue = theValue + theTime; 
	}
    window.opener.Transfer(theValue);
    window.close()
}

var URL = location.href;
var setToNow = true;
var i = URL.indexOf("?");
if (i != -1) {
		URL = URL.slice(i+1)
		if(URL == "onlyDate") {
			onlyDate = true;
		} else {
			i = URL.indexOf("&")
			if(URL.slice(0, i) == "onlyDate") {
				onlyDate = true;
				URL = URL.slice(i+1);
			} 
			setToNow = false;
			i = URL.indexOf("&");
		    theMonth = 1*URL.slice(6,i)
		    theYear = 1*URL.slice(i+6, i+10)
		    if(!onlyDate) theTime = URL.slice(i+16)
		}
} 

if (setToNow) {
        var pomDate= new Date();
        theMonth = pomDate.getMonth();
        theYear = pomDate.getFullYear();
        if(!onlyDate) {
	        var mins = pomDate.getMinutes();
	        if(mins < 10) mins = "0" + mins;
	        var hours = pomDate.getHours();
	        if(hours < 10) hours = "0" + hours;
	        theTime = hours + ":" + mins;
        }
}

WriteNavigation(theMonth,theYear);
WriteMonthTable(theMonth,theYear);
if(!onlyDate) WriteTime(theTime);

</script>
</body>
</html>